package org.daidai.abstrusewriting.homepage.hot.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import org.daidai.abstrusewriting.homepage.hot.model.ADinformationData;

import java.util.List;



/**
 * Created by Administrator on 2016/11/2.
 */

public class FootPictureAdapter extends PagerAdapter {
    private List<ADinformationData.ADinformation> mList;
    private Context mContext;

    public FootPictureAdapter(Context context, List<ADinformationData.ADinformation> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return 3000;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View ret = null;
        ImageView imageView = new ImageView(mContext);
        int size = mList.size();
        Picasso.with(mContext)
                .load(mList.get(position%size).getCover())
                .config(Bitmap.Config.ARGB_8888)
                .into(imageView);
        container.addView(imageView);
        ret = imageView;
        return ret;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(((View) object));
    }
}
